package de.fhluebeck.oop.gps.cmd;

import java.util.List;

import de.fhluebeck.oop.gps.common.Constants;
import de.fhluebeck.oop.gps.common.DependencyManager;
import de.fhluebeck.oop.gps.entity.Poi;
import de.fhluebeck.oop.gps.service.IPoiService;

/**
 * 
 * Option zur Selektion von Poi
 * Diese Option erwartet Parameter in Form von lat,lng,distance
 *
 * @author Ogün Bilge, Leif Hitzschke
 * @version 1.00, 13.11.2009
 * 
 */
public class ShowPoiOption extends Option {

	private final static String KEY = "-showpoi";
	private Option successor;
	
	private final IPoiService poiService ;
	
	public ShowPoiOption(Option successor) {
		this.successor = successor;
		poiService = (IPoiService) DependencyManager.locate(Constants.POI_SERVICE_DEP_NAME);
	}
	
	@Override
	void execute(String value) {
		
		List<Poi> pois = poiService.readAll();
		
		for (Poi poi : pois) {
			String out = new StringBuilder("Poi id:") //
			.append(poi.getId()) //
			.append(", name:") //
			.append(poi.getName()) //
			.append(", lat:") //
			.append(poi.getLat()) //
			.append(", lng:") //
			.append(poi.getLng()) //
			.toString();
			System.out.println(out);
		}
	}

	@Override
	Option getSuccessor() {
		return successor;
	}

	@Override
	boolean isApplicable(String key) {
		return KEY.equals(key);
	}
}
